package org.jeecg.modules.test.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.constant.RabbitMqConstant;
import org.jeecg.modules.test.entity.HeightLevelUser;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Date;

/**
 * RabbitMq消息测试
 *
 * @author ZhangYu
 * @date 2023/9/24 23:45
 */
@Slf4j
@Api(tags = "RabbitMq消息测试")
@RestController
@RequestMapping("/mq/test")
public class RabbitMqTestController {

    @Resource
    private RabbitTemplate rabbitTemplate;

    /**
     * fanout广播模式发送mq测试消息
     *
     * @return 发送信息
     */
    @ApiOperation("fanout广播模式发送mq测试消息")
    @PostMapping("/fanout/send/message")
    public Result<?> sendFanoutTestMqMessage() {
        rabbitTemplate.convertAndSend(RabbitMqConstant.FANOUT_EXCHANGE, "", HeightLevelUser.builder().birth(new Date()).name("张宇").age(1).six(1).build());
        log.info("---------------------------------------------------------------------fanout广播模式发送mq测试，消息已发送");
        return Result.OK();
    }

    /**
     * direct路由模式发送mq测试消息
     *
     * @return 发送信息
     */
    @ApiOperation("direct路由模式发送mq测试消息")
    @PostMapping("/direct/send/message")
    public Result<?> sendDirectTestMqMessage() {
        rabbitTemplate.convertAndSend(RabbitMqConstant.DIRECT_EXCHANGE, RabbitMqConstant.ROUTING_ONE, HeightLevelUser.builder().birth(new Date()).name("张宇").age(1).six(1).build());
        log.info("---------------------------------------------------------------------direct路由模式发送mq测试，消息已发送");
        return Result.OK();
    }

    /**
     * topic主题模式发送mq测试消息
     *
     * @return 发送信息
     */
    @ApiOperation("topic主题模式发送mq测试消息")
    @PostMapping("/topic/send/message")
    public Result<?> sendTopicTestMqMessage() {
        rabbitTemplate.convertAndSend(RabbitMqConstant.TOPIC_EXCHANGE, RabbitMqConstant.TOPIC_ROUTING_THREE, HeightLevelUser.builder().birth(new Date()).name("张宇").age(1).six(1).build());
        log.info("----------------------------------------------------------------------topic主题模式发送mq测试，消息已发送");
        return Result.OK();
    }

}
